package com.xique.park.controller.client.web.service.biz.service.impl;

import com.github.pagehelper.PageInfo;
import com.xique.common.core.utils.OrikaUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.park.bean.domain.ParkIn;
import com.xique.park.bean.domain.ParkOn;
import com.xique.park.controller.client.web.bean.dto.ParkInOut;
import com.xique.park.controller.client.web.bean.request.ClientParkOnListRequest;
import com.xique.park.controller.client.web.bean.request.WebClientInOutRecordRequest;
import com.xique.park.controller.client.web.bean.vo.WxAppParkOnVO;
import com.xique.park.controller.client.web.service.biz.service.IWxAppRecordBizService;
import com.xique.park.mapper.ParkInMapper;
import com.xique.park.service.service.IParkOnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxAppRecordBizServiceImpl implements IWxAppRecordBizService {

    @Autowired
    private IParkOnService parkOnService;

    @Autowired
    private ParkInMapper parkInMapper;

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

    @Override
    public AjaxResult getParkOnList(ClientParkOnListRequest request) {
        ParkOn parkOn = new ParkOn();
        parkOn.setPlate(request.getPlate());
        parkOn.setParkId(SecurityUtils.getParkId());
        //TODO 请求参数有增加
        List<ParkOn> parkOnList = parkOnService.selectParkOnList(parkOn);
        TableDataInfo dataTable = getDataTable(parkOnList);
        List<WxAppParkOnVO> parkOnVOS = OrikaUtil.converts(parkOnList,WxAppParkOnVO.class);
        dataTable.setRows(parkOnVOS);
        return AjaxResult.success(parkOnVOS);
    }

    @Override
    public AjaxResult getInOutList(WebClientInOutRecordRequest request) {
        ParkIn parkIn = new ParkIn();
        parkIn.setParkId(SecurityUtils.getParkId());
        //TODO 请求参数有增加
        List<ParkInOut> parkInOuts = parkInMapper.selectParkInOutList(parkIn);
        //TODO VO转化
        return AjaxResult.success(parkInOuts);
    }

}
